﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace CivonyHelper
{
    public partial class MainForm : Form
    {
        private int CurrentServerSelection = 3;
        private PythonPlugins PluginSystem;

        public MainForm()
        {
            InitializeComponent();
            this.serverselect.SelectedIndex = CurrentServerSelection - 1;
            this.GameWindow.Navigate("http://www.civony.com");
        }

        private void serverselect_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.CurrentServerSelection = serverselect.SelectedIndex;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.GameWindow.Navigate(String.Format("http://{0}.civony.com", this.CurrentServerSelection 
                + 1));
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            PluginSystem = new PythonPlugins(this);
            PopulateAddonList();
        }


        private void PopulateAddonList()
        {
            DirectoryInfo di = new DirectoryInfo("./Plugins/");
            FileInfo[] rgFiles = di.GetFiles("*.py");
            foreach (FileInfo fi in rgFiles)
            {
                AddonList.Items.Add(fi.Name);
            }
        }

        private void AboutButton_Click(object sender, EventArgs e)
        {
            new About().Show();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            string FPath = (string)AddonList.SelectedItem;
            PluginSystem.RunPlugin("./Plugins/" + FPath);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            AddonList.Items.Clear();
            PopulateAddonList();
        }

        private void MainPageButton_Click(object sender, EventArgs e)
        {
            this.GameWindow.Navigate("www.civony.com");
        }
    }
}
